<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Packer.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - Compressor example file
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font>
<font color="#3A3966">UseBriefLZPacker</font>() <font color="#3A3966">; Small and fast packer
</font>
<b><font color="#3A3966">If</font></b> <font color="#3A3966">ReadFile</font>(0,<font color="#3A3966"> OpenFileRequester</font>("Choose a file to compress", "", "*.*", 0))
  FileLength =<font color="#3A3966"> Lof</font>(0)
  
  <font color="#3A3966">; Allocate the 2 memory buffers needed for compression..
</font>  <font color="#3A3966">;
</font>  *Source =<font color="#3A3966"> AllocateMemory</font>(FileLength)
  *Target =<font color="#3A3966"> AllocateMemory</font>(FileLength)
  <b><font color="#3A3966">If</font></b> FileLength <b><font color="#3A3966">And</font></b> *Source <b><font color="#3A3966">And</font></b> *Target
<font color="#3A3966">    ReadData</font>(0, *Source, FileLength) <font color="#3A3966">; Read the whole file in the memory buffer
</font>
    <font color="#3A3966">; Compress the file, which is in memory (and use a timer to see the time spend by compression..)
</font>    <font color="#3A3966">;
</font>    CompressedLength =<font color="#3A3966"> CompressMemory</font>(*Source, FileLength, *Target, FileLength)
    <b><font color="#3A3966">If</font></b> CompressedLength

      DecompressedLength =<font color="#3A3966"> UncompressMemory</font>(*Target, CompressedLength, *Source, FileLength)
      <b><font color="#3A3966">If</font></b> DecompressedLength = FileLength
<font color="#3A3966">        MessageRequester</font>("Info", "De/Compression succeded:"+<font color="#924B72">#LF$</font>+<font color="#924B72">#LF$</font>+"Old size: "+<font color="#3A3966">Str</font>(FileLength)+<font color="#924B72">#LF$</font>+"New size: "+<font color="#3A3966">Str</font>(CompressedLength))
      <b><font color="#3A3966">EndIf</font></b>
    <b><font color="#3A3966">Else</font></b>
<font color="#3A3966">      MessageRequester</font>("Error", "Can't compress the file")
    <b><font color="#3A3966">EndIf</font></b>
    
<font color="#3A3966">    FreeMemory</font>(*Source)
<font color="#3A3966">    FreeMemory</font>(*Target)
    
  <b><font color="#3A3966">EndIf</font></b>
  
<font color="#3A3966">  CloseFile</font>(0)
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">End</font></b>
</font></pre>
</body></html>
